package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.BuyPlan;
import com.qf.entity.PayRecord;
import com.qf.service.PayRecordService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author Hulboy
 * @date 2024/7/25
 * @desc --- 代码敲烂 月薪过万 ---
 */

@RestController
@CrossOrigin
@RequestMapping("/payRecord/")
public class PayRecordController {
    @Autowired
    private PayRecordService service;

    @GetMapping("/findAll")
    public R findAll(@RequestParam HashMap<String, String> map) {

        // HashMap<String,String> 是 “ 存键值对用的集合 ”
        // map 是 HashMap<String, String> 类的一个实例。
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum, pageSize);

        // R是返回值类型


        List<PayRecord> list = service.findAll(map);
        PageInfo<PayRecord> info = new PageInfo<>(list);

        return R.ok(info);
    }

    @GetMapping("/delBatch")
    public R delBatch(@RequestParam List<Integer> ids) {
        System.out.println("删除这些："+ids);
        boolean isok = service.delBatch(ids);
        return R.ok(isok);
    }

    @PostMapping("/addPayRecord")
    public R addPayRecord(@RequestBody PayRecord pay) {
        System.out.println("打印pay = " + pay);   // 接收到一行？
        boolean isOk = service.addPayRecord(pay);

        System.out.println("isOk = " + isOk);
        return R.ok(isOk);
    }


    @PostMapping("/edit")
    public R edit(@RequestBody PayRecord pay) {
        System.out.println("打印pay = " + pay);   // 接收到一行？
        boolean isOk = service.edit(pay);
        System.out.println("isOk = " + isOk);
        return R.ok(isOk);
    }

    @GetMapping("/delete")
    public R deleteById(int id) {
        System.out.println("删除这些："+id);
        boolean isOk = service.deleteById(id);
        return R.ok(isOk);
    }

}
